package main

import "fmt"

func produce(id int, ch chan string, quitSub chan int) {
	for i := 0; i < 1000; i++ {
		ch <- fmt.Sprintf("msg:%d:%d", id, i)
	}
	quitSub <- id
}
func main() {
	c1 := make(chan string, 1)         //定义有缓冲的通道，容量为1
	quitForSelect := make(chan int, 1) //用于通知退出for select循环
	go produce(1, c1, quitForSelect)
ForEnd:
	for { //使用select来等待这两个通道的值，然后输出
		select {
		case msg1 := <-c1:
			fmt.Println(msg1)
		case q := <-quitForSelect:
			fmt.Println("got quit tag for Gorouting id:", q)
			if q == 1 {
				fmt.Println("end to quit Main ")
				break ForEnd
			}
		}
	}
	fmt.Println("exit from main")
}
